<template>
	<view class="container">
		<!-- 毛玻璃背景 -->
		<view class="blur-bg"></view>

		<!-- 顶部标题 -->
		<view class="header">
			<text class="title">村村通快递代取</text>
			<text class="subtitle">便民服务 · 快递送到家</text>
		</view>

		<!-- 主内容区 -->
		<scroll-view class="main-content" scroll-y>
			<!-- 取件信息卡片 -->
			<view class="card pickup-info">
				<view class="card-header">
					<text class="card-title">取件信息</text>
					<view class="card-decoration"></view>
				</view>

				<!-- 取件码 -->
				<view class="input-group">
					<text class="input-label">取件码</text>
					<input class="input" type="text" v-model="pickupCode" placeholder="请输入快递取件码"
						placeholder-class="placeholder" @focus="focusInput('pickupCode')" @blur="blurInput" />
				</view>

				<!-- 取件地址选择 -->
				<view class="input-group">
					<text class="input-label">取件地点</text>
					<view class="address-options">
						<view v-for="(address, index) in pickupAddresses" :key="index" class="address-option"
							:class="{active: selectedAddress === address}" @click="selectAddress(address)">
							{{address}}
							<view class="address-icon">
								<view class="icon-circle"></view>
							</view>
						</view>
					</view>
				</view>
			</view>

			<!-- 包裹限制说明卡片 -->
			<view class="card limit-card">
				<view class="card-header">
					<text class="card-title">包裹限制说明</text>
					<view class="card-decoration"></view>
				</view>

				<view class="limit-content">
					<view class="limit-item">
						<uni-icons type="info" size="24" color="#e74c3c" class="limit-icon"></uni-icons>
						<text class="limit-text">我们仅代取小包裹，请确认您的包裹符合以下要求：</text>
					</view>

					<view class="limit-details">
						<view class="detail-item">
							<uni-icons type="checkmarkempty" size="20" color="#2ecc71" class="detail-icon"></uni-icons>
							<text class="detail-text">尺寸：最长边不超过40厘米</text>
						</view>
						<view class="detail-item">
							<uni-icons type="checkmarkempty" size="20" color="#2ecc71" class="detail-icon"></uni-icons>
							<text class="detail-text">重量：不超过2公斤</text>
						</view>
						<view class="detail-item">
							<uni-icons type="closeempty" size="20" color="#e74c3c" class="detail-icon"></uni-icons>
							<text class="detail-text">不接受：液体、易碎品、违禁品</text>
						</view>
					</view>

					<view class="limit-tip">
						<text>如您的包裹超出上述限制，请自行取件，感谢理解！</text>
					</view>
				</view>
			</view>

			<!-- 收件人信息卡片 -->
			<view class="card recipient-info">
				<view class="card-header">
					<text class="card-title">收件人信息</text>
					<view class="card-decoration"></view>
				</view>

				<!-- 当前收件人信息展示 -->
				<view class="current-recipient" v-if="recipient">
					<view class="info-row">
						<text class="info-label">姓名：</text>
						<text class="info-value">{{recipient.name}}</text>
					</view>
					<view class="info-row">
						<text class="info-label">电话：</text>
						<text class="info-value">{{recipient.phone}}</text>
					</view>
					<view class="info-row">
						<text class="info-label">地址：</text>
						<text class="info-value">{{recipient.address}}</text>
					</view>
				</view>

				<!-- 无收件人提示 -->
				<view class="no-recipient" v-else>
					<text>请先完善个人信息</text>
				</view>
			</view>

			<!-- 备注信息 -->
			<view class="card remarks-card">
				<view class="input-group">
					<text class="input-label">备注信息</text>
					<textarea class="textarea" v-model="remarks" placeholder="如有特殊要求请在此说明（如：快递较小请小心保管等）"
						placeholder-class="placeholder" @focus="focusInput('remarks')" @blur="blurInput" />
				</view>
			</view>
		</scroll-view>

		<!-- 提交按钮 -->
		<view class="submit-btn-container">
			<button class="submit-btn" :class="{disabled: !formValid}" :disabled="!formValid"
				@click="handleSubmit">
				<text class="btn-text">提交代取申请</text>
			</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				pickupCode: '',
				pickupAddresses: ['快乐星汉堡店', '福旺超市', '王打挂小学兔喜超市'],
				selectedAddress: '',
				remarks: '',
				recipient: null,
				focusedInput: null
			}
		},
		created() {
			this.loadRecipient();
		},
		computed: {
			formValid() {
				return (
					this.pickupCode &&
					this.selectedAddress &&
					this.recipient
				)
			}
		},
		methods: {
			// 从本地缓存加载收件人
			loadRecipient() {
				try {
					const userInfo = uni.getStorageSync('userInfo');
					if (userInfo) {
						this.recipient = {
							name: userInfo.name || '',
							phone: userInfo.phone || '',
							address: userInfo.address || ''
						};
					}
				} catch (e) {
					console.error('加载收件人失败:', e);
				}
			},
			
			// 选择地址
			selectAddress(address) {
				this.selectedAddress = address;
			},
			
			// 输入框聚焦
			focusInput(inputName) {
				this.focusedInput = inputName;
			},
			
			// 输入框失焦
			blurInput() {
				this.focusedInput = null;
			},
			
			// 提交表单
			handleSubmit() {
				// 准备订单数据
				const orderData = {
					pickupCode: this.pickupCode,
					pickupAddress: this.selectedAddress,
					recipient: this.recipient,
					remarks: this.remarks,
					submitTime: new Date().toLocaleString()
				};
				
				// 跳转到订单确认页面
				uni.navigateTo({
					url: `/pages/orderConfirm/orderConfirm?data=${encodeURIComponent(JSON.stringify(orderData))}`
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	/* 基础容器和背景 */
	.container {
		position: relative;
		min-height: 100vh;
		padding: 20rpx;
		overflow: hidden;
		font-family: 'PingFang SC', 'Microsoft YaHei', sans-serif;
	}

	.blur-bg {
		position: absolute;
		top: 0;
		left: 0;
		width: 100%;
		height: 100%;
		background: linear-gradient(92deg, rgb(255 216 216) 0%, rgb(210 236 255 / 90%) 100%);
		backdrop-filter: blur(20rpx);
		z-index: 0;
	}

	/* 标题样式 */
	.header {
		position: relative;
		z-index: 1;
		margin-bottom: 40rpx;
		padding-top: 40rpx;
		text-align: center;

		.title {
			display: block;
			font-size: 42rpx;
			font-weight: bold;
			color: #2c3e50;
			margin-bottom: 10rpx;
			letter-spacing: 2rpx;
			text-shadow: 0 2rpx 4rpx rgba(0, 0, 0, 0.05);
		}

		.subtitle {
			font-size: 24rpx;
			color: #7f8c8d;
			letter-spacing: 1rpx;
		}
	}

	/* 卡片通用样式 */
	.card {
		background: rgba(255, 255, 255, 0.85);
		border-radius: 24rpx;
		padding: 30rpx;
		margin-bottom: 30rpx;
		backdrop-filter: blur(10rpx);
		box-shadow: 0 8rpx 24rpx rgba(0, 0, 0, 0.05);
		border: 1rpx solid rgba(255, 255, 255, 0.4);

		.card-header {
			display: flex;
			justify-content: space-between;
			align-items: center;
			margin-bottom: 30rpx;
			position: relative;

			.card-title {
				font-size: 32rpx;
				font-weight: bold;
				color: #2c3e50;
				position: relative;
				padding-left: 20rpx;

				&::before {
					content: '';
					position: absolute;
					left: 0;
					top: 50%;
					transform: translateY(-50%);
					width: 6rpx;
					height: 30rpx;
					background: #3498db;
					border-radius: 3rpx;
				}
			}

			.card-decoration {
				position: absolute;
				right: 0;
				top: 50%;
				transform: translateY(-50%);
				width: 80rpx;
				height: 4rpx;
				background: linear-gradient(90deg, transparent, #3498db);
				border-radius: 2rpx;
			}
		}
	}

	/* 包裹限制说明卡片 */
	.limit-card {
		.limit-content {
			.limit-item {
				display: flex;
				align-items: center;
				margin-bottom: 20rpx;

				.limit-icon {
					margin-right: 12rpx;
				}

				.limit-text {
					font-size: 26rpx;
					color: #e74c3c;
					font-weight: 500;
				}
			}

			.limit-details {
				margin-bottom: 20rpx;
				padding-left: 44rpx;

				.detail-item {
					display: flex;
					align-items: center;
					margin-bottom: 16rpx;

					.detail-icon {
						margin-right: 12rpx;
					}

					.detail-text {
						font-size: 26rpx;
						color: #2c3e50;
					}
				}
			}

			.limit-tip {
				padding-left: 44rpx;
				font-size: 24rpx;
				color: #7f8c8d;
				font-style: italic;
			}
		}
	}

	/* 输入框组样式 */
	.input-group {
		margin-bottom: 30rpx;

		.input-label {
			display: block;
			font-size: 28rpx;
			color: #7f8c8d;
			margin-bottom: 16rpx;
			font-weight: 500;
		}

		.input {
			width: 100%;
			height: 80rpx;
			padding: 0 24rpx;
			border: 1rpx solid rgba(52, 152, 219, 0.3);
			border-radius: 16rpx;
			font-size: 28rpx;
			color: #2c3e50;
			background: rgba(255, 255, 255, 0.8);
			transition: all 0.3s;

			&[data-focused="true"] {
				height: 100rpx;
				background: rgba(255, 255, 255, 0.95);
				box-shadow: 0 4rpx 16rpx rgba(52, 152, 219, 0.15);
			}
		}

		.textarea {
			width: 100%;
			height: 150rpx;
			padding: 20rpx 24rpx;
			border: 1rpx solid rgba(52, 152, 219, 0.3);
			border-radius: 16rpx;
			font-size: 28rpx;
			color: #2c3e50;
			background: rgba(255, 255, 255, 0.8);
			transition: all 0.3s;

			&[data-focused="true"] {
				height: 180rpx;
				background: rgba(255, 255, 255, 0.95);
				box-shadow: 0 4rpx 16rpx rgba(52, 152, 219, 0.15);
			}
		}

		.placeholder {
			color: #bdc3c7;
			font-size: 28rpx;
		}
	}

	/* 地址选择按钮 */
	.address-options {
		display: flex;
		flex-wrap: wrap;
		gap: 20rpx;

		.address-option {
			flex: 1;
			min-width: 200rpx;
			height: 80rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			background: rgba(255, 255, 255, 0.8);
			border-radius: 16rpx;
			font-size: 26rpx;
			color: #7f8c8d;
			border: 1rpx solid rgba(52, 152, 219, 0.3);
			position: relative;
			overflow: hidden;
			transition: all 0.3s;

			&.active {
				background: rgba(52, 152, 219, 0.1);
				color: #2c3e50;
				font-weight: 500;
				border-color: #3498db;

				.address-icon .icon-circle {
					background: #3498db;
				}
			}

			.address-icon {
				position: absolute;
				right: 16rpx;
				top: 50%;
				transform: translateY(-50%);
				width: 32rpx;
				height: 32rpx;
				border-radius: 50%;
				border: 1rpx solid rgba(52, 152, 219, 0.5);
				display: flex;
				align-items: center;
				justify-content: center;

				.icon-circle {
					width: 20rpx;
					height: 20rpx;
					border-radius: 50%;
					background: transparent;
					transition: all 0.3s;
				}
			}
		}
	}

	/* 当前收件人信息 */
	.current-recipient {
		background: rgba(255, 255, 255, 0.8);
		border-radius: 16rpx;
		padding: 24rpx;
		border: 1rpx solid rgba(52, 152, 219, 0.2);

		.info-row {
			display: flex;
			margin-bottom: 12rpx;
			font-size: 28rpx;

			&:last-child {
				margin-bottom: 0;
			}

			.info-label {
				color: #7f8c8d;
				width: 120rpx;
			}

			.info-value {
				color: #2c3e50;
				flex: 1;
			}
		}
	}

	.no-recipient {
		text-align: center;
		padding: 40rpx 0;
		color: #bdc3c7;
		font-size: 28rpx;
	}

	/* 提交按钮 */
	.submit-btn-container {
		position: fixed;
		bottom: 40rpx;
		left: 0;
		width: 100%;
		padding: 0 30rpx;
		z-index: 2;

		.submit-btn {
			width: 100%;
			height: 100rpx;
			border-radius: 50rpx;
			background: linear-gradient(90deg, #3498db, #2980b9);
			color: white;
			font-size: 32rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			border: none;
			box-shadow: 0 8rpx 24rpx rgba(41, 128, 185, 0.3);
			transition: all 0.3s;

			&:active {
				transform: scale(0.98);
			}

			&.disabled {
				background: #bdc3c7;
				box-shadow: none;
			}

			.btn-text {
				font-weight: bold;
			}
		}
	}
</style>